import axios from 'axios'

axios.defaults.baseURL = 'http://localhost:3000/api';
export function fetchPost(url, params, config) {
  console.log(params)
  return new Promise((resolve, reject) => {
    axios.post(url, params, config)
      .then(response => {
        resolve(response.data);
      }, err => {
        reject(err);
      })
      .catch((error) => {
        reject(error)
      })
  })
}
export function fetchGet(url, paramObj) {
  return new Promise((resolve, reject) => {
    let param = { params: paramObj }
    axios.get(url, param)
      .then(response => {
        resolve(response.data);
      }, err => {
        reject(err);
      })
      .catch((error) => {
        reject(error)
      })
  })
}
export default {
  //后台登录接口
  login(username, password) {
    let params = {
      username,
      password
    };
    return fetchPost('/user/login', params);
  },
  cet4() {
    return fetchGet('/personal/cet4');
  },
  cet6() {
    return fetchGet('/personal/cet6');
  },
  updateCet(id, degree) {
    let params = {
      id,
      degree
    };
    return fetchPost('/personal/updateCet', params);
  },
  getMessage() {
    return fetchGet('/message/getMessage');
  },
  transWord(word) {
    let params = {
      word
    };
    return fetchPost('/message/transWord', params);
  }

}